import type { EChartsOption } from 'echarts';
// 合并图表数据
export function mergeOptions(
  newOptions: EChartsOption,
  staticOptions: EChartsOption,
): EChartsOption {
  const keys: string[] = [...Object.keys(staticOptions), ...Object.keys(newOptions)];

  const options: EChartsOption = {};
  for (const key of keys) {
    const optionsValue = staticOptions[key];
    const newOptionsValue = newOptions[key];
    // 判断集中类型的属性值，以便做不同的合并处理
    if (optionsValue && newOptionsValue) {
      if (optionsValue instanceof Array && newOptionsValue instanceof Array) {
        options[key] = [...optionsValue, ...newOptionsValue];
      } else if (optionsValue instanceof Object && newOptionsValue instanceof Object) {
        options[key] = { ...optionsValue, ...newOptionsValue };
      } else {
        options[key] = newOptionsValue;
      }
    } else {
      options[key] = optionsValue ? optionsValue : newOptionsValue;
    }
  }
  return options;
}